package team.archai.nexus.boot.auth.util;

import org.springframework.lang.Nullable;
import team.archai.nexus.boot.auth.exception.AuthFailException;
import team.archai.nexus.boot.auth.exception.ExpiredException;
import team.archai.nexus.boot.auth.exception.InvalidException;
import team.archai.nexus.boot.auth.exception.JwtException;


/**
 * @description: 自定义jwt认证断言
 * @author: lishibin
 * @create: 2020-06-29 23:08
 **/
public class AuthAssert {

    /**
     * @program: AuthAssert
     * @description: 校验jwt相关参数为null? 如果为null 抛出 JwtException 传入的message
     * @author: lishibin
     * @create: 11:44 PM
     **/
    public static void jwtParamNull(@Nullable Object param, String message) {
        if (null == param) {
            throw new InvalidException(message);
        }
    }

    /**
     * @program: AuthAssert
     * @description: 校验sign 是否有效
     * @author: lishibin
     * @create: 11:51 PM
     **/
    public static void signEffective(@Nullable Object sign, String message) {
        if (null == sign) {
            throw new InvalidException(message);
        }
    }

    /**
     * @program: AuthAssert
     * @description: 校验token是否有效
     * @author: lishibin
     * @create: 11:52 PM
     **/
    public static void jwtParamEffective(@Nullable Object param, String message) {
        if (null == param) {
            throw new InvalidException(message);
        }
    }

    /**
     * @program: AuthAssert
     * @description: 校验jwt参数是否过期
     * @author: lishibin
     * @create: 11:54 PM
     **/
    public static void jwtParamNoExpired(@Nullable Object param, String message) {
        if (null == param) {
            throw new ExpiredException(message);
        }
    }

    /**
     * @program: AuthAssert
     * @description:
     * @author: lishibin
     * @create: 1:32 AM
     **/
    public static void jwtParamNoExpired(boolean flag, String message) {
        if (flag) {
            throw new ExpiredException(message);
        }
    }

    /**
     * @program: AuthAssert
     * @description:
     * @author: lishibin
     * @create: 19:29
     **/
    public static void authParam(boolean flag, String message) {
        if (flag) {
            throw new AuthFailException(message);
        }
    }

    /**
    * @program: AuthAssert
    * @description:
    * @author: lishibin
    * @create: 19:30
    **/
    public static void authParam(@Nullable Object param, String message) {
        if (param == null) {
            throw new AuthFailException(message);
        }
    }
}
